/**
 * @author Chenjd
 * 2010-06-10
 */
$(function(){

    // 默认的淡入速率，单位ms
    var DEFAULT_FADE_IN_SPEED = 256;
	
    // 默认的淡出速率，单位ms
    var DEFAULT_FADE_OUT_SPEED = 64;
	
    // 上次弹出的菜单
    var lastPop = null;
	
    // 所有的弹出菜单的选择字符串
    var POP_UP_MENU_SEL_STR = "ul.navigate>li>ul";
    
	/*
	 * 给弹出菜单添加样式
	 */
    $(POP_UP_MENU_SEL_STR).addClass("thnbd2");
    
    $("body").click(closeOpenedMenu);
    $("iframe").load(function() {
    	$(this).contents().find("body").click(closeOpenedMenu);
    });
    
    function closeOpenedMenu(){
        if (lastPop != null) {
            $(POP_UP_MENU_SEL_STR).fadeOut(DEFAULT_FADE_OUT_SPEED);
            $("ul.navigate>li").removeClass("hover");
            lastPop = null;
        }
        
    }
    
	/*
	 * 划过导航菜单项时，弹出对应菜单
	 */
    $("ul.navigate>li").hover(function(){
        if (lastPop == this) {
            return;
        }
        
        $(POP_UP_MENU_SEL_STR).fadeOut(DEFAULT_FADE_OUT_SPEED);
        $("ul.navigate>li").removeClass("hover");
        $(this).addClass("hover");
        
        var ul = $(this).children("ul");
        var offset = $(this).position();
        var height = $(this).height();
        ul.css({
            "top": offset.top,
            "left": offset.left,
            "clip": "rect(" + height + "px auto auto auto)",
            "padding-top": height
        });
        ul.fadeIn(DEFAULT_FADE_IN_SPEED);
        
        lastPop = this;
        
    });
    
    
});


